package com.example.simple.work.controller;

import com.example.simple.work.entity.Checking;
import com.example.simple.work.entity.EmployeeMessage;
import com.example.simple.work.entity.User;
import com.example.simple.work.service.ICheckingService;
import com.example.simple.work.service.IUserService;
import com.example.simple.work.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("checking")
public class CheckingController extends BaseController{

    @Autowired
    private ICheckingService checkingService;

    /**
     * 插入员工考勤信息
     * */
    @RequestMapping("insert")
    @CrossOrigin
    @ResponseBody
    public JsonResult<Void> insert (@RequestBody Checking checking){
        System.out.println(checking);
        checkingService.insert(checking);
        return new JsonResult<>(OK);
    }

    /**
     * 删除员工考勤信息
     * */
    @RequestMapping("delete")
    @CrossOrigin
    @ResponseBody
    public JsonResult<Void> delete (@RequestBody Integer id){
        checkingService.delete(id);
        return new JsonResult<>(OK);
    }

    /** 查询所有员工信息 */
    @RequestMapping("list")
    @CrossOrigin
    public JsonResult<List<Checking>> list (){
        List<Checking> list = checkingService.findAllCheckingData();
        return new JsonResult<>(200,list);
    }

    /** 根据员工姓名查询员工考勤信息 */
    @RequestMapping("find")
    @CrossOrigin
    @ResponseBody
    public JsonResult<List<Checking>> findMessageByEmployeeName (@RequestBody String employeeName){
        System.out.println(employeeName);
        List<Checking> list = checkingService.findCheckingByEmployeeName(employeeName);
        return new JsonResult<>(200,list);
    }

    /**
     * 修改员工信息
     * */
    @RequestMapping("change")
    @CrossOrigin
    @ResponseBody
    public JsonResult<Void> change (@RequestBody Checking checking){
        Integer id = checking.getId();
        checkingService.changeChecking(id,checking);
        return new JsonResult<>(OK);
    }

    /**
     * 批量插入员工信息
     * */
    @RequestMapping("insertList")
    @CrossOrigin
    @ResponseBody
    public JsonResult<Void> insertList (@RequestBody List<Checking> checkingList){
        System.out.println(checkingList);
        checkingService.insertList(checkingList);
        return new JsonResult<>(OK);
    }

}
